package com.sgcc.fj.pmos.e_fj_home.presenter;

import com.alibaba.android.arouter.utils.TextUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.common.utils.ListPageUtil;
import com.sgcc.fj.pmos.common.utils.UserManager;
import com.sgcc.fj.pmos.e_fj_home.bean.ByConditionBean;
import com.sgcc.fj.pmos.e_fj_home.bean.DisclosureApplyBean;
import com.sgcc.fj.pmos.e_fj_home.contract.InfomationTypeListContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class InfomationTypeListPresenter extends BasePresenter<InfomationTypeListContract.View>
        implements InfomationTypeListContract.Presenter {


    @Override
    public void getByCondition(String infoCode) {
        Map<String, Object> params = new HashMap<>();
        String infoCodes[] = infoCode.split(",");
        params.put("infoCodes", infoCodes);
        params.put("marketId", "PDBLN");
        HttpRequestUtils.getInstance().request(params, HttpInterConst.INFORMATION_DISCLOSURE_GETBYCONDITION, new MvpNetCallback<ByConditionBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().getByConditionFailed();
            }

            @Override
            public void onResponse(ByConditionBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if ("0".equals(response.getStatus())) {
                        getView().getByConditionSuccess(response);
                    } else {
                        if (!TextUtils.isEmpty(response.getMessage())) {
                            ToastUtils.showShort(response.getMessage());
                        }
                    }
                }
            }
        });
    }

    @Override
    public void queryIpDisclosureApply(String infoCode, String columnNos, int pageNum, boolean isloading) {
        Map<String, Object> params = new HashMap<>();
        String informationIds[] = columnNos.split(",");
        Map<String, Object> data = new HashMap<>();
        String operateTimeArr[] = {};
        data.put("operateTimeArr", operateTimeArr);
        data.put("customInfoName", "");
        data.put("sourceName", "");
        data.put("marketId", "PDBLN");
        data.put("columnNos", informationIds);
        if ("fdqyQyjbxx".equals(infoCode) || "dlyhQyjbxx".equals(infoCode) || "sdgsQyjbxx".equals(infoCode)) {
            data.put("isUsed", "1");
        }
        params.put("data", data);
        Map<String, Object> pageInfo = new HashMap<>();
        String pageSizes1[] = {"20", "50", "100", "200", "500", "1000"};
        int pageSizes[] = {20, 50, 100, 200, 500, 1000};
        pageInfo.put("pageSizes1", pageSizes1);
        pageInfo.put("pageSizes", pageSizes);
        pageInfo.put("pageSize", 20);
        pageInfo.put("pageNum", new ListPageUtil(pageNum, ListPageUtil.pageSize2).getTotalPage());
        params.put("pageInfo", pageInfo);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.INFORMATION_DISCLOSURE_QUERYIPDISCLOSUREAPPLY, new MvpNetCallback<DisclosureApplyBean>(getView(), isloading) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().getQueryIpDisclosureApplyFailed();
            }

            @Override
            public void onResponse(DisclosureApplyBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if ("0".equals(response.getStatus())) {
                        getView().getQueryIpDisclosureApplySuccess(response);
                    } else {
                        if (!TextUtils.isEmpty(response.getMessage())) {
                            ToastUtils.showShort(response.getMessage());
                        }
                    }
                }
            }
        });
    }
}
